package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.PracticeClassStudentDTO;
import com.ruoyi.training.dto.StudentPracticeCheckInDTO;
import com.ruoyi.training.vo.AppointmentResultVO;
import com.ruoyi.training.vo.PracticeClassStudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.PracticeClassStudent;
import com.ruoyi.training.service.IPracticeClassStudentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实践预约班级学生中间Controller
 *
 * @author WorrilessGo
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/practiceClassStudent")
public class PracticeClassStudentController extends BaseController
{
    @Autowired
    private IPracticeClassStudentService practiceClassStudentService;

    /**
     * 查询实践预约班级学生中间列表
     */
    @RequiresPermissions("training:practiceClassStudent:list")
    @GetMapping("/list")
    public TableDataInfo list(PracticeClassStudent practiceClassStudent)
    {
        startPage();
        List<PracticeClassStudent> list = practiceClassStudentService.selectPracticeClassStudentList(practiceClassStudent);
        return getDataTable(list);
    }

    /**
     * 查询班级学员的实践签到情况
     */
    @GetMapping("/class/{classId}")
    public TableDataInfo getStudentPracticeCheckIn(@PathVariable String classId)
    {
        startPage();
        List<StudentPracticeCheckInDTO> list = practiceClassStudentService.getStudentPracticeCheckIn(classId);
        return getDataTable(list);
    }

    /**
     * 新增接口：查询实践预约的学员预约情况
     * lqx
     */
    @Log(title = "查询实践预约学员情况", businessType = BusinessType.OTHER)
    @GetMapping("/students")
    public AjaxResult getPracticeClassStudents( PracticeClassStudentVo practiceClassStudentVo) {
        startPage();
        List<PracticeClassStudentDTO> list = practiceClassStudentService.getPracticeClassStudents(practiceClassStudentVo);
        return AjaxResult.success(list);
    }

    /**
     * 新增接口：查询当前班级实践预约学员情况
     * 查询参数 班级id 实践预约id
     * lqx
     */
    @GetMapping("/validClassList")
    public ResponseEntity<AppointmentResultVO> selectClassStudentAppointmentStatus(PracticeClassStudentDTO practiceClassStudentDTO) {
        // 从查询对象中获取参数
        AppointmentResultVO result = practiceClassStudentService.selectClassStudentAppointmentStatus(practiceClassStudentDTO);
        return ResponseEntity.ok(result);
    }

    /**
     * 导出实践预约班级学生中间列表
     */
    @RequiresPermissions("training:practiceClassStudent:export")
    @Log(title = "实践预约班级学生中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeClassStudent practiceClassStudent)
    {
        List<PracticeClassStudent> list = practiceClassStudentService.selectPracticeClassStudentList(practiceClassStudent);
        ExcelUtil<PracticeClassStudent> util = new ExcelUtil<PracticeClassStudent>(PracticeClassStudent.class);
        util.exportExcel(response, list, "实践预约班级学生中间数据");
    }

    /**
     * 获取实践预约班级学生中间详细信息
     */
    @RequiresPermissions("training:practiceClassStudent:query")
    @GetMapping(value = "/{practiceClassStudentId}")
    public AjaxResult getInfo(@PathVariable("practiceClassStudentId") String practiceClassStudentId)
    {
        return success(practiceClassStudentService.selectPracticeClassStudentByPracticeClassStudentId(practiceClassStudentId));
    }

    /**
     * 新增实践预约班级学生中间
     */
    @RequiresPermissions("training:practiceClassStudent:add")
    @Log(title = "实践预约班级学生中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeClassStudent practiceClassStudent)
    {
        return toAjax(practiceClassStudentService.insertPracticeClassStudent(practiceClassStudent));
    }

    /**
     * 7.10.6添加预约
     * lqx
     */
    @PostMapping("/addPractice")
    public AjaxResult addPractice(@RequestBody List<PracticeClassStudent> practiceClassStudentList)
    {
        return toAjax(practiceClassStudentService.insertPracticeClassStudentList(practiceClassStudentList));
    }

    /**
     * 修改实践预约班级学生中间
     */
    @RequiresPermissions("training:practiceClassStudent:edit")
    @Log(title = "实践预约班级学生中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeClassStudent practiceClassStudent)
    {
        return toAjax(practiceClassStudentService.updatePracticeClassStudent(practiceClassStudent));
    }

    /**
     * 取消预约，修改预约状态为2
     */
    @PutMapping("editAppointmentStatus")
    public AjaxResult editAppointmentStatus(@RequestBody String[] practiceClassStudentIds)
    {
        return toAjax(practiceClassStudentService.editAppointmentStatus(practiceClassStudentIds));
    }

    /**
     * 删除实践预约班级学生中间
     */
    @RequiresPermissions("training:practiceClassStudent:remove")
    @Log(title = "实践预约班级学生中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{practiceClassStudentIds}")
    public AjaxResult remove(@PathVariable String[] practiceClassStudentIds)
    {
        return toAjax(practiceClassStudentService.deletePracticeClassStudentByPracticeClassStudentIds(practiceClassStudentIds));
    }
}
